<?php
// 批量剔除action
namespace Beerus\Modules\DesignerRanking\Actions;
use Encore\Admin\Grid\Tools\BatchAction;

class BatchRemove extends BatchAction {
	protected int $iRankingMonth;
    protected int $iRankingCityAreaCode;
    protected string $sMainRankingName;
    protected string $sSubRankingName;

    public function __construct(
	    int $iRankingMonth,
        int $iRankingCityAreaCode,
        string $sMainRankingName,
        string $sSubRankingName
    ) {
        $this->iRankingMonth = $iRankingMonth;
        $this->iRankingCityAreaCode = $iRankingCityAreaCode;
        $this->sMainRankingName = $sMainRankingName;
        $this->sSubRankingName = $sSubRankingName;
    }

    public function script() {
        $sBatchRemoveUrl = route('rank.batch_remove');
        return <<<EOT
            $('{$this->getElementClass()}').on('click', function() {
                $.ajax({
                    method: 'post',
                    url: '{$sBatchRemoveUrl}',
                    data: {
                        _token: LA.token,
                        ids: $.admin.grid.selected(),
                        ranking_month: {$this->iRankingMonth},
                        ranking_city_area_code: {$this->iRankingCityAreaCode},
                        main_ranking_name: '{$this->sMainRankingName}',
                        sub_ranking_name: '{$this->sSubRankingName}'  
                    },
                    success: function(result) {
                        $.pjax.reload('#pjax-container');
                        if (result.status == true) { 
                            toastr.success('操作成功');
                        } else {
                            toastr.error(result.message);
                        }
                    }
                });
            });
        EOT;
    }
}
